/**
 * JAVACC DEMO 1.0
 * @copy right dwusoft company All rights reserved. 
 * @Package com.apache.uct.service.plugins  
 */
package com.apache.member.service.plugins;

import org.apache.log4j.Logger;

import com.apache.api.manager.PluginConnector;
import com.apache.api.vo.ParamsVo;
import com.apache.api.vo.ResultEntity;
import com.apache.cache.util.Validator;
import com.apache.member.entity.Member;
import com.apache.member.manager.MemberManager;

public class MemberInfoPlugin implements PluginConnector {

	private Logger log = Logger.getLogger(MemberInfoPlugin.class);

	private MemberManager memberManager;

	public Object execute(ParamsVo vo) throws Exception {
		ResultEntity result = new ResultEntity();
		try {
			result.setResult("true");
			String memberId = String.valueOf(vo.getParams("memberId"));
			if (Validator.isNotNull(memberId)) {
				memberInfo(result, vo);
			} else {
				result.setMessage("没有可用方法被执行！");
			}
		} catch (Exception e) {
			result.setResult("false");
			log.error("执行机构查询失败 ", e);
			result.setMessage("机构查询失败！");
		}
		return result;
	}

	/**
	 * description: 会员信息查询
	 */
	private void memberInfo(ResultEntity result, ParamsVo vo) {
		String memberId = getParamStr(vo, "memberId");
		if (Validator.isNotNull(memberId)) {
			ParamsVo<Member> memberVo = new ParamsVo<Member>();
			memberVo.setInfoId(memberId);
			memberVo.setMethodKey("ByIdForService");
			Object obj = memberManager.getInfoById(memberVo);
			result.setEntity(obj);
			result.setMessage("查询成功");
		}
	}

	private String getParamStr(ParamsVo vo, String attrName) {
		return Validator.getDefaultStr(String.valueOf(vo.getParams(attrName)), "");
	}

	public void setMemberManager(MemberManager memberManager) {
		this.memberManager = memberManager;
	}

}
